package com.exercise.memberscheduling.security;

import com.exercise.memberscheduling.repository.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @Author:STY
 * @Description:从数据库中获取用户信息
 */
@Service
public class MyUserDetailsService implements UserDetailsService {
    @Autowired
    private MemberService service;

    @Override
    public UserDetails loadUserByUsername(String username)throws UsernameNotFoundException
    {
        UserLogin userLogin = service.SelAdminPassword();
        userLogin.setId("admin");
        userLogin.setAuthority("admin");
        userLogin.setAuthorities(AuthorityUtils.commaSeparatedStringToAuthorityList(userLogin.getAuthority()));
        return userLogin;
    }
}

